package rexsee.core.browser.clazz;

import java.util.ArrayList;

import rexsee.core.browser.Browser;
import rexsee.core.browser.RexseeUrl;
import android.content.Context;

public abstract class FilterListener {
	public final String name;
	public final String type;
	protected final ArrayList<String> urls;
	public FilterListener(String name, String type) {
		this.name = name;
		this.type = type;
		urls = new ArrayList<String>();
	}
	public abstract void run(Context context, Browser browser, String url);
	public boolean containsUrl(String url) {
		url = RexseeUrl.cleanUrl_(url);
		for (int i = 0; i < urls.size(); i++) {
			if (url.startsWith(urls.get(i))) return true;
		}
		return false;
	}
	public void addUrl(String url) {
		urls.add(RexseeUrl.cleanUrl_(url));
	}
	public String getUrls() {
		String rtn = "";
		for (int i = 0; i < urls.size(); i++) {
			if (i > 0) rtn += ",";
			rtn += "\"" + urls.get(i) + "\"";
		}
		rtn = "[" + rtn + "]";
		return rtn;
	}
	public String getUrl(int index) {
		return urls.get(index);
	}
	public int getNumberOfUrls() {
		return urls.size();
	}
	public void clearUrls() {
		urls.clear();
	}
	public void removeUrl(String url) {
		urls.remove(url);
	}
}
